<template>
  <el-dialog
    title="添加付款计划"
    :close-on-click-modal="false"
    append-to-body
    :visible.sync="visible"
    lock-scroll
    width="600px"
    @close="clearData"
  >
    <el-form
      ref="elForm"
      :model="dataForm"
      :rules="rules"
      label-width="120px"
      label-position="right"
    >
      <el-form-item label="计划名称" prop="planName">
        <el-input v-model="dataForm.planName" placeholder="请输入计划名称" />
      </el-form-item>
      <el-form-item label="付款比例" prop="paymentRatio">
        <el-input-number
          v-model="dataForm.paymentRatio"
          controls-position="right"
          :min="1"
          :max="100"
          class="percent-input"
          style="width: 100%"
          placeholder="请输入付款比例"
        />
      </el-form-item>
      <el-form-item label="付款金额" prop="paymentAmount">
        <el-input-number
          v-model="dataForm.paymentAmount"
          controls-position="right"
          :min="1"
          class="percent-input1"
          style="width: 100%"
          placeholder="请输入付款金额"
        />
      </el-form-item>
      <el-form-item label="应付款日期" prop="accountsPayableDate">
        <el-date-picker
          v-model="dataForm.accountsPayableDate"
          type="date"
          style="width: 100%"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
        />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="dataForm.remark" placeholder="请输入备注" />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button @click="subAddPay" type="primary">确定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { addPaymentPlan } from "@/api/contract/contractOrg";
export default {
  props: [],
  data() {
    return {
      visible: false,
      dataForm: {},
      rules: {
        planName: [{ required: true, message: "请输入", trigger: "blur" }],
        paymentRatio: [{ required: true, message: "请输入付款比例", trigger: "blur" }],
        paymentAmount: [{ required: true, message: "请输入付款金额", trigger: "blur" }],
        accountsPayableDate: [
          { required: true, message: "请选择付款日期", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    init(id) {
      this.dataForm.contractId = id || 0;
      this.visible = true;
    },
    // 添加付款计划
    subAddPay() {
      this.$refs["elForm"].validate((valid) => {
        if (valid) {
          addPaymentPlan(this.dataForm).then((res) => {
            this.clearData();
            this.$emit("refreshAddPaymentSchedule");
          });
        }
      });
    },
    clearData() {
      this.dataForm.contractId = null;
      this.dataForm.planName = null;
      this.dataForm.paymentRatio = null;
      this.dataForm.paymentAmount = null;
      this.dataForm.accountsPayableDate = null;
      this.dataForm.remark = null;
      this.resetForm("elForm");
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .percent-input::after {
  content: "%";
  position: absolute;
  right: 50px;
  top: 50%;
  transform: translateY(-50%);
}

::v-deep .percent-input1::after {
  content: "元";
  position: absolute;
  right: 50px;
  top: 50%;
  transform: translateY(-50%);
}
</style>
